package com.fanrui.code.util;

public class FCDTools {
	
	public final static double PI 	= 3.14159265354;
	private final static double D2R 	= 0.017453 ;
	private final static double a2 	= 6378137.0;
	private final static double e2 	= 0.006739496742337;
	
	public static double Distance(FCD_Point pt1, FCD_Point pt2) {
		if(pt1.lng == pt2.lng && pt1.lat == pt2.lat ) {
            return 0.0;
        } else {
            double fdLambda =(pt1.lng - pt2.lng) * D2R;
            double fdPhi = (pt1.lat - pt2.lat) * D2R;
            double fPhimean = ((pt1.lat + pt2.lat) / 2.0) * D2R;
            double fTemp = 1 - e2 * (Math.pow (Math.sin(fPhimean),2));
            double fRho = (a2 * (1 - e2)) / Math.pow (fTemp, 1.5);
            double fNu = a2 / (Math.sqrt(1 - e2 * (Math.sin(fPhimean) * Math.sin(fPhimean))));
            double fz = Math.sqrt (Math.pow(Math.sin(fdPhi / 2.0), 2) +
            		Math.cos(pt2.lat * D2R) * Math.cos( pt1.lat*D2R ) * Math.pow( Math.sin(fdLambda / 2.0),2));
            fz = 2 * Math.asin(fz);
            double fAlpha = Math.cos(pt2.lat * D2R) * Math.sin(fdLambda) * 1 / Math.sin(fz);
            fAlpha = Math.asin (fAlpha);
            double fR = (fRho * fNu) / ((fRho * Math.pow( Math.sin(fAlpha),2)) + (fNu * Math.pow( Math.cos(fAlpha),2)));
            return fz * fR;
        }
	}
}
